import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collection;

import edu.ucla.cs.typecast.cache2.CacheManager;
import edu.ucla.cs.typecast.cache2.CachedObject;


public class CacheServer {
    public static void main(String[] args) { 
        try { 
            CacheManager.getInstance().enableCacheService(); 
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 
            while(true) { 
                System.out.print("Enter return to print the current cached objects:"); 
                reader.readLine(); 
                Collection<CachedObject> cachedObjects = CacheManager.getInstance().getCachedObjects(); 
                for(CachedObject co : cachedObjects) { 
                    System.out.print("ContentSource=" + co.getContentSourceEndPoint()); 
                    System.out.print(",GUID=" + co.getGuid()); 
                    System.out.print(", Timeout=" + co.getTimeout()); 
                    System.out.print(", Types=["); 
                    Class[] types = co.getTypes(); 
                    for(Class type: types) { 
                        System.out.print(type + " ");
                    }
                    System.out.println("], Implementation=" + co.getImplementationClass()); 
                }
            }
        } catch(Throwable t) { 
            t.printStackTrace(); 
        }
    }
}
